/**
 * @author 卢永昌
 * @description 解决element-ui组件库中的message并发问题。
 */

 import {Message} from 'element-ui';

 let messageInstance = null;
 //重置message实体
 const resetMessage = (options) => {
     if (messageInstance) {
         messageInstance.close()
     }
     messageInstance = Message(options)
 };
 //对每种类型进行修改
 ['error', 'success', 'info', 'warning'].forEach(type => {
     resetMessage[type] = options => {
         if (typeof options === 'string') {
             options = {
                 message: options
             }
         }
         options.type = type
         return resetMessage(options)
     }
 })
 export const message = resetMessage